<%-- 
    Document   : login
    Created on : Sep 10, 2014, 9:26:56 AM
    Author     : bean
--%>

<%@page import="DAL.StudentDAO"%>
<%@page import="DAL.MyConnection"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <style>
            table, th, td {
		border-collapse: collapse;
	}
	th, td {
		padding: 15px;
	}
        </style>

    </head>
    <body style="background-image: url('http://localhost:8080/ftico_project/pic/hinh-nen-hd-dep-cho-may-tinh-canh-bien-wallpaper-12.jpg')" >
        <div align = "center">
        <h1>Login</h1>
        </div>
        <div align="center">
            <form action="#" method="POST">
                <table  border="1" style="background-color: white" >
                    <tr>
                        <td >
                            <table>
                                <tr>
                                    <td>Account : </td>
                                    <td><input type="text" name="Account"></td>
                                </tr>
                                <tr>
                                    <td>Password : </td>
                                    <td><input type="text" name="Password"></td>
                                </tr>
                                <tr>
                                    <td></td>
                                    <td><input type="submit" value="Login"></td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>


            </form>
            <%
                try {

                    Connection con = MyConnection.getConnection();
                    StudentDAO studentDAO = new StudentDAO(con);
                    String sql = request.getParameter("Account");
                    String sql2 = request.getParameter("Password");
                    if (sql != "") {
                        if (sql != null) {
                            String query = "select * from login where acc ='" + sql + "'";
                            int result = studentDAO.checkUser(query);

                            if (result == 1) {
                                if (sql2 != "") {
                                    try {
                                        Connection con2 = MyConnection.getConnection();
                                        StudentDAO studentDAO2 = new StudentDAO(con2);
                                        String query2 = "select * from login where pass ='" + sql2 + "'";

                                        int result2 = studentDAO2.checkPass(query2);

                                        if (result2 == 1) {
                                            response.sendRedirect("menu.html");
                                        } else {
                                            out.println("Wrong pass");
                                        }
                                    } catch (Exception ex) {
                                        out.println(ex.getMessage());
                                    }

                                } else {
                                    out.println("Please enter pass");
                                }

                            } else {
                                out.println("account dose not exsit!");
                            }
                        }



                    } else {
                        out.println("please enter account!");
                    }


                } catch (Exception ex) {
                    out.println(ex.getMessage());
                }
            %>

        </div>
    </body>
</html>
